<template>
  <el-dialog
    v-model="dialogVisible"
    :title="title"
    width="30%"
    :before-close="handleClose"
  >
    <div class="tab6-dialog-hetong">
      <el-form
        ref="ruleFormRef"
        :model="ruleForm"
        :rules="rules"
        label-width="110px"
      >
        <el-form-item prop="num" label="期数">
          <el-input placeholder="期数" v-model="ruleForm.num" />
        </el-form-item>
        <el-form-item prop="plan_money" label="计划回款金额">
          <el-input placeholder="计划回款金额" v-model="ruleForm.plan_money" />
        </el-form-item>
        <el-form-item prop="plan_date" label="计划回款金额">
          <el-date-picker
            style="width: 100%"
            v-model="ruleForm.plan_date"
            type="date"
            placeholder="计划回款日期"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>

        <el-form-item prop="" label="备注" style="width: 100%">
          <el-input
            placeholder="备注"
            type="textarea"
            :rows="2"
            v-model="ruleForm.remark"
          />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
        <el-button type="primary" @click="submit"> 提交 </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { receivablesPlanSaveApi } from "@/plugins/api/customer/manage/tab6";

const props = defineProps({
  dataInfo: {
    type: Object,
    default: {},
  },
});

let ruleForm = ref({});
let rules = {
  num: [
    {
      required: true,
      message: "输入期数",
      trigger: "blur",
    },
  ],
  plan_money: [
    {
      required: true,
      message: "计划回款金额",
      trigger: "change",
    },
  ],
  plan_date: [
    {
      required: true,
      message: "计划回款日期",
      trigger: "change",
    },
  ],
};
let dialogVisible = ref(false);
function handleClose(done) {
  ElMessageBox.confirm("是否确定关闭此对话框?")
    .then(() => {
      done();
    })
    .catch(() => {});
}
let title = ref("");
let submitType = ref("");
let ruleFormRef = ref(null);
function initFun(row) {
  if (ruleFormRef.value) {
    ruleFormRef.value.resetFields();
  }
  ruleForm.value = { ...row };
  title.value = "编辑";
  dialogVisible.value = true;
}

const emit = defineEmits(["refreshList"]);
function submit() {
  if (!ruleFormRef.value) return;
  ruleFormRef.value.validate((valid, fields) => {
    if (valid) {
      let obj = { ...ruleForm.value };
      receivablesPlanSaveApi(obj).then((res) => {
        ElMessage.success("编辑成功！");
        dialogVisible.value = false;
        emit("refreshList");
      });
    }
  });
}

onMounted(() => {});
defineExpose({
  initFun,
});
</script>
<style scoped lang="scss">
.tab6-dialog-hetong {
  h4 {
    margin: 0;
    margin-bottom: 20px;
  }

  :deep(.el-form-item) {
    width: 100%;
    margin-right: 0;
  }

  .goods-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;

    span {
      margin-right: 20px;
    }
  }
}
</style>
